#pragma once

class VertexCache : public Singleton<VertexCache>
{
	std::map<ui32, Vertex3FCNT2*> m_vertexCache;
public:
	VertexCache() { }
	void AddVertices(ui32 indexX, ui32 indexZ, ADTModel* pParent, Vertex3FCNT2* pVertices)
	{
		ui32 e = indexX + indexZ * 100 + pParent->m_indexX * 10000 + pParent->m_indexZ * 1000000;
		if(m_vertexCache[e])
			delete [] m_vertexCache[e];
		m_vertexCache[e] = new Vertex3FCNT2[145];
		memcpy(m_vertexCache[e], pVertices, 145 * Vertex3FCNT2::stride);
	}

	Vertex3FCNT2* GetVertices(ui32 indexX, ui32 indexZ, ADTModel* pParent)
	{
		ui32 e = indexX + indexZ * 100 + pParent->m_indexX * 10000 + pParent->m_indexZ * 1000000;
		return m_vertexCache[e];
	}
};

#define sCache (*VertexCache::GetInstance())